<?php


namespace app\admin\model;


class AppUpdateLog extends Common
{
    /**
     * 为了数据库的整洁，同时又不影响Model和Controller的名称
     * 我们约定每个模块的数据表都加上相同的前缀，比如CRM模块用crm作为数据表前缀
     */
    protected $name = 'admin_app_update_log';
    protected $createTime = 'create_time';
    protected $updateTime = 'create_time';


    /**
     * 获取更新记录
     * @param $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author Mr.Li
     * @create 2021-08-19 14:04
     */
    public function getList($request)
    {
        $request['page'] = $request['page'] ?? 1;
        $request['limit'] = $request['limit'] ?? 20;
        if(!$request['page']){
            $request['page'] = 1;
        }
        $sqlQuery = self::where('id','>',0);
        $dataCount = $sqlQuery->count();
        $list = [];
        if ($dataCount) {
            $list  = self::order('id DESC')
                ->when(!(isset($request['no_page']) && $request['no_page']) ,function($query) use ($request){
                    $query->limit(($request['page'] - 1) * $request['limit'], $request['limit']);
                })
                ->select()->toArray();
        }
        $data['dataCount'] = $dataCount;  // 总数
        $data['list'] = $list;
        return $data;
    }

}
